<template>
  <div>

    <el-row >
           <el-col :span="24">
            <el-form   class="demo-form-inline">
              <el-form-item >
                  <el-input  placeholder="请输入企业名称" v-model="enterpriseName" style="float:left;width:300px;margin-left:200px"></el-input>
                  <el-button icon="el-icon-search"  type="primary"  style="float:left" @click="doSearchBtn"></el-button>
                  <el-button icon="el-icon-plus" circle style="margin-left:700px" type="danger" @click="doAdd"></el-button>新增融资企业
               </el-form-item>
                 </el-form>
                 
           </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-table
    :data="tableData"
    border
    style="width: auto;">
    <el-table-column
      type="index"
      label="序号"
      align="center"
      width="50"
    ></el-table-column>
    <el-table-column
      label="融资企业名称"
      align="center"
      >
      <template slot-scope="scope">
        <el-link type="primary" @click="doSee(scope.row)">{{ scope.row.enterpriseName }}</el-link>
      </template>
    </el-table-column>
    <el-table-column
    prop="legal"
      label="法人"
      align="center">
    </el-table-column>
    <el-table-column
      prop="legalPhone"
      label="手机号"
      align="center">
    </el-table-column>
    <el-table-column
      prop="legalId"
      label="法人身份证号"
      align="center">
    </el-table-column>
    <el-table-column
      label="营业执照号"
      align="center">
      <template slot-scope="scope">
        <el-link type="primary" @click="seeImg(scope.row)">{{ scope.row.businessLicense }}</el-link>
      </template>
    </el-table-column>
   
    <el-table-column
      label="审核状态"
      align="center">
      <template slot-scope="scope" v-if="scope.row.platformState==0">待审核
    </template>
    </el-table-column>
   
    <el-table-column
    label="操作"
    align="center"
    width="500">
    <el-button type="primary">修改信息</el-button>
    <template slot-scope="scope">
      <el-button type="primary" @click="pass(scope.row)">通过</el-button>
      <el-button type="danger" @click="noPass(scope.row)">不通过</el-button>
    </template>
    </el-table-column>
  </el-table>
      </el-col>
    </el-row>

    <el-row>
           <el-col :span="24" :offset="6">
            <el-pagination
              
              background
              @size-change="sizeChange"
              @current-change="currentChange"
              :current-page="pageNum"
              :page-sizes="[3, 6, 9]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
            </el-col>
        </el-row>

        <el-dialog  title="企业详情" :visible.sync="dialogFormVisible" >
    <el-row>
      <el-col :span="10" >
        <el-form :model="dialogform" style="font-size:35px">
          <el-form-item label="企业编码:" label-width="80px">
             <template>{{ dialogform.enterpriseId }}</template>
           </el-form-item>
          <el-form-item label="企业名称:" label-width="80px">
            <template>{{ dialogform.enterpriseName }}</template>
          </el-form-item>
          <el-form-item label="法人:" label-width="80px">
            <template>{{ dialogform.legal }}</template>
          </el-form-item>
          <el-form-item label="手机号:" label-width="80px">
            <template>{{ dialogform.legalPhone }}</template>
          </el-form-item>
          <el-form-item label="身份证号:" label-width="80px">
            <template>{{ dialogform.legalId }}</template>
          </el-form-item>
          <el-form-item label="营业执照图片:" label-width="80px">
            <img :src="dialogform.businessLicenseImage" style="width:300px;heigth:350px"/>
          </el-form-item>
          <el-form-item label="营业执照号:" label-width="80px">
            <template>{{ dialogform.businessLicense }}</template>
            
          </el-form-item>
          <el-form-item label="注册资金:" label-width="80px">
            <template>{{ dialogform.registeredCapital }}</template>
          </el-form-item>
          <el-form-item label="核心企业审核:" label-width="80px">
            <template v-if="dialogform.coreState==0">待审核</template>
            <template v-if="dialogform.coreState==1">通过</template>
            <template v-if="dialogform.coreState==2">未通过</template>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  
    <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
    </div>
  
  </el-dialog>

  <el-dialog  title="营业执照图片" :visible.sync="showing" >
    <el-row>
      <el-col :span="20" >
            <img :src="imgPath" style="width:900px;heigth:800px"/>
      </el-col>
    </el-row>
  
    <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="showing = false">确 定</el-button>
    </div>
  </el-dialog>

  <el-dialog  title="融资企业录入" :visible.sync="dialogFormAdd" >
    <el-row>
      <el-col :span="10" >
        <el-form :model="dialogAdd" style="font-size:35px">

          <el-form-item label="企业名称:" label-width="80px">
            <el-input v-model="dialogAdd.enterpriseName" placeholder="请输入企业名称"></el-input>
          </el-form-item>
          <el-form-item label="法人:" label-width="80px">
            <el-input v-model="dialogAdd.legal" placeholder="请输入企业法人"></el-input>
          </el-form-item>
          <el-form-item label="手机号:" label-width="80px">
            <el-input v-model="dialogAdd.legalPhone" placeholder="请输入企业法人手机号"></el-input>
          </el-form-item>
          <el-form-item label="身份证号:" label-width="80px">
            <el-input v-model="dialogAdd.legalId" placeholder="请输入企业法人身份证号"></el-input>
          </el-form-item>
          <el-form-item label="营业执照图片:" label-width="80px">
            <el-upload
            class="upload-demo"
            action="/api/uploadimg"
            :headers="headers"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :file-list="fileList1"
            list-type="picture"
            :on-success="handleAvatarSuccess">
            <el-button size="small" type="primary" >点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
          </el-upload>
          </el-form-item>
          <el-form-item label="营业执照号:" label-width="80px">
            <el-input v-model="dialogAdd.businessLicense" placeholder="请输入营业执照号"></el-input>
          </el-form-item>
          <el-form-item label="注册资金:" label-width="80px">
            <el-input v-model="dialogAdd.registeredCapital" placeholder="请输入企业注册资金"></el-input>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormAdd = false">取 消</el-button>
    <el-button type="primary" @click="doSave">确 定</el-button>
  </div>
  </el-dialog>
  
  </div>

</template>

<script>
export default {
    data(){
        return{
          fileList1:[],
            headers:{
              'jwt':localStorage.getItem('jwt')
            },
            dialogFormAdd:false,
            showing:false,
            dialogFormVisible:false,
            tableData:[],
            pageNum:1,
            pageSize:3,
            goodName:'',
            total:0,
            enterpriseName:'',
            dialogform:{
                enterpriseId:'',
                enterpriseName:'',
                legal:'',
                legalPhone:'',
                legalId:'',
                businessLicenseImage:'',
                businessLicense:'',
                registeredCapital:'',
                coreState:'',
                platformState:''
            },
            dialogAdd:{
                enterpriseName:'',
                legal:'',
                legalPhone:'',
                legalId:'',
                businessLicenseImage:'',
                businessLicense:'',
                registeredCapital:'',
                coreState:'0',
                platformState:'1'
            },
            imgPath:''
        }
    },
    created(){
        this.getFinance()
    },
    methods:{
        handleAvatarSuccess(res, file){
          console.log(res)
          this.dialogAdd.businessLicenseImage = res.msg
      },
        handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
        pass(row){
            let that = this
            let param = {}
            param.enterpriseId = row.enterpriseId
            param.platformState = 1
            let record = {}
            record.financeId = row.enterpriseId
            record.auditResult = 1

        this.$confirm('审核通过, 请确认?', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
            this.$axios.post('api/finance/modifyFinance',param,{headers:{'jwt':localStorage.getItem('jwt')}})
            .then(res=>{
                if(res.data.code==200){
                    that.$axios.post('/api/auditRecord/insertAuditRecord',record,{headers:{'jwt':localStorage.getItem('jwt')}})
                    .then(res=>{
                        if(res.data.code==200){
                            that.getFinance()
                            that.$message({
                                message:'审核通过',
                                type:'success'
                            })
                        }else{
                            that.$message({
                                message:'网络异常',
                                type:'error'
                            })
                        }
                    })
                }else{
                    that.$message({
                                message:'网络异常',
                                type:'error'
                            })
                }
            })
        }).catch(() => {
          
        });
            
        },
        noPass(row){
            let that = this
            let param = {}
            param.enterpriseId = row.enterpriseId
            param.platformState = 2
            let record = {}
            record.financeId = row.enterpriseId
            record.auditResult = 2

        this.$confirm('审核不通过, 请确认?', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
            this.$axios.post('api/finance/modifyFinance',param,{headers:{'jwt':localStorage.getItem('jwt')}})
            .then(res=>{
                if(res.data.code==200){
                    that.$axios.post('/api/auditRecord/insertAuditRecord',record,{headers:{'jwt':localStorage.getItem('jwt')}})
                    .then(res=>{
                        if(res.data.code==200){
                            that.getFinance()
                            that.$message({
                                message:'审核未通过',
                                type:'warning'
                            })
                        }else{
                            that.$message({
                                message:'网络异常',
                                type:'error'
                            })
                        }
                    })
                }else{
                    that.$message({
                                message:'网络异常',
                                type:'error'
                            })
                }
            })
        }).catch(() => {
          
        });
            
        },
        seeImg(row){
            this.imgPath = row.businessLicenseImage
            this.showing = true
        },
        doSave(){
            this.$axios.post('api/finance/saveFinance',this.dialogAdd,{headers:{'jwt':localStorage.getItem('jwt')}})
            .then(res =>{
                if(res.data.code==200){
                    this.$message({
                                message:'录入成功',
                                type:'success'
                            })
                    this.getFinance()
                    this.dialogFormAdd = false
                }else{
                    this.$message({
                                message:'网络异常',
                                type:'error'
                    })
                    this.dialogFormAdd = false
                }
            })
        },
        doAdd(){
            this. dialogAdd={
                enterpriseName:'',
                legal:'',
                legalPhone:'',
                legalId:'',
                businessLicenseImage:'',
                businessLicense:'',
                registeredCapital:'',
                coreState:'0',
                platformState:'1'
            }
            this.dialogFormAdd = true
        },
        doSearchBtn(){
            this.pageNum = 1
            this.getFinance()
        },
        currentChange(p){
          this.pageNum=p
        this.getFinance()
        },
        sizeChange(p){
          this.pageNum=1
          this.pageSize=p
          this.getFinance()
        },
        doSee(row){
            this.dialogform = row
            this.dialogFormVisible = true

        },
        getFinance(){
            let param={}
            param.pageNum = this.pageNum
            param.pageSize = this.pageSize
            let data ={}
            data.enterpriseName = this.enterpriseName
            data.platformState = 0
            data.coreState = -1
            param.data = data
            this.$axios.post('/api/finance/queryFinanceInfoByPage',param,{headers:{'jwt':localStorage.getItem('jwt')}})
            .then(res=>{

                let pageDate = res.data.data
                 this.tableData = pageDate.list
                this.pageNum = pageDate.pageNum
                this.pageSize = pageDate.pageSize
                this.total = pageDate.total
            })

        }
    }

}
</script>

<style scoped>

</style>